package main

import (
	"flag"
	"gitee.com/gam6it/SecToolkit/qingteng/wanxiang"
	"log"
	"time"
)

func getHosts(c *wanxiang.Client) {
	var opt = wanxiang.HostFilterOption{
		OS:          "linux",
		Page:        0,
		Size:        1,
		AgentStatus: "0,1",
	}
	i, hosts, err := c.GetHostByPage(opt)
	log.Println("获取指定主机结果：", i, hosts, err)
}

func getAllHosts(c *wanxiang.Client) {
	var opt = wanxiang.HostFilterOption{}
	i, hosts, err := c.GetHosts(opt)
	log.Println("获取所有主机结果：", i, len(*hosts), err)
}

func getIpInfo(c *wanxiang.Client, ip string) {
	log.Println(c.GetHostByIP(ip))
}

func main() {
	var url, username, password, ip string
	flag.StringVar(&url, "url", "", "URL地址")
	flag.StringVar(&username, "u", "", "用户名")
	flag.StringVar(&password, "p", "", "密码")
	flag.StringVar(&ip, "ip", "", "密码")
	flag.Parse()
	if url == "" || username == "" || password == "" {
		log.Fatalf("输入不能为空！\n")
	}
	client, err := wanxiang.NewClient(url, username, password, 60*time.Second)
	if err != nil {
		log.Fatalf("创建客户端失败：%v\n", err)
	}
	// log.Println("开始更新linux主机信息")
	// fmt.Println(client.HostFresh(wanxiang.HostOSTypeLinux))
	log.Println("开始获取部分Host")
	getHosts(client)
	// log.Println("开始获取所有Host")
	getAllHosts(client)
	// getIpInfo(client, ip)

}
